package me.militch.quickcore.sample.host;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.util.List;

import javax.inject.Inject;

import me.militch.quickcore.core.HasDaggerInject;
import me.militch.quickcore.core.QuickActivity;
import me.militch.quickcore.event.ListViewEvent;
import me.militch.quickcore.execute.ModelAndListView;
import me.militch.quickcore.execute.ModelAndView;
import me.militch.quickcore.mvp.model.ModelHelper;
import me.militch.quickcore.sample.ActivityComponent;
import me.militch.quickcore.sample.R;
import me.militch.quickcore.sample.bean.UserInfo;
import me.militch.quickcore.sample.host.fragment.TestFragment;
import me.militch.quickcore.sample.service.MainService;

public class MainActivity extends QuickActivity implements
        MainContract.View,
        HasDaggerInject<ActivityComponent>,
        View.OnClickListener{
    private Button button;
    @Inject
    MainPresenter mainPresenter;
    @Override
    public void onClick(View v) {
        mainPresenter.simpleRequest();
//        mainPresenter.findText();
//        ModelAndListView.create(this,modelHelper).request(modelHelper.getService(MainService.class).requestTest(),new ListViewEvent<UserInfo>());

    }

    @Override
    public int layout() {
        return R.layout.activity_test;
    }

    @Override
    public void initView(Bundle savedInstanceState) {

        button = $(R.id.text_btn,this);
        TestFragment fragment = TestFragment.newInstance();
        replacef(R.id.test_content, fragment);
    }


    @Override
    public void showToastMsg(String msg) {
        Toast.makeText(this,msg,Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mainPresenter.detachView();
    }

    @Override
    public void bindData(List<UserInfo> data) {
        showToastMsg("--数据来了"+ data.get(0).getName());
    }

    @Override
    public void inject(ActivityComponent activityComponent) {
        activityComponent.inject(this);
    }
}
